package com.nbclass.controller;

/*
       AUTHOR: Jarvie -> YYDS
  CREATE TIME: 2024/9/14   
*/

import com.nbclass.domain.Result;
import com.nbclass.domain.User;
import com.nbclass.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class StudentController {
    @Autowired
    private UserService userService;

    @RequestMapping("/studentCardView")
    public String main(){
        return "/views/child/studentCard";
    }
    @ResponseBody
    @RequestMapping("/studentCard")
    public Result card(){
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        userService.card(userDetails.getUsername());
        return Result.Success();
    }

    @RequestMapping("/studentTestView")
    public String studentTestView(){
        return "/views/child/studentTest";
    }
    @RequestMapping("/studentManagementView")
    public String studentManagementViewView(){
        return "/views/child/studentManagement";
    }

    @ResponseBody
    @RequestMapping("/studentManagement")
    public Result<List<User>> studentManagement(){
        return Result.Success(userService.queryAll());
    }
    @ResponseBody
    @RequestMapping("/queryStudentByName")
    public Result<List<User>> queryStudentByName(@RequestParam("realname") String realname,@RequestParam("cname") String cname,@RequestParam("page") String page,@RequestParam("limit") String limit){

        return Result.Success(userService.queryAllByNameAndClass(realname,cname,page,limit));
    }


}
